﻿package display
{
	import controller.Controller;
	import display.DisplayHighLight;
	import events.DisplayEvent;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.GraphicsSolidFill;
	import flash.geom.ColorTransform;
	import utils.FullScreenScrollBar;
	
	public class DisplayBackGround extends MovieClip
	{
		private var bg:Sprite;
		private var itemAlpha:Number = 1;
		private var control:Controller;
		private var highLight:DisplayHighLight;
		
		private var myColor:ColorTransform = new ColorTransform;
		
		public function DisplayBackGround(ctr:Controller)
		{
			control = ctr;
			control.addEventListener(DisplayEvent.COLOR_CHANGED, onColorChanged);
			control.addEventListener(DisplayEvent.ALPHA_CHANGED, onAlphaChanged);
			
			build();
		}
		
		private function build():void
		{
			bg = new Sprite;
			bg.graphics.beginFill(0xffffff,1);
			bg.graphics.drawRect(0,0,785,498);
			bg.graphics.endFill();
			
			highLight = new DisplayHighLight(control, 'background', 498, 785);
			
			addChild(bg);
			addChild(highLight);
		}
		
		private function changeColor():void
		{
			bg.transform.colorTransform = myColor;
			
			changeAlpha();
		}
		
		private function changeAlpha():void
		{
			bg.alpha = itemAlpha;
		}
		
		private function onHighlight(e:DisplayEvent):void
		{
			if (e.data.item == 'background')
			{
				switch(e.data.state)
				{
					case 'over':
					
					break;
					
					case 'out':
					
					break;
				}
			}
		}
		
		private function onColorChanged(e:DisplayEvent):void
		{
			switch(e.data.itemCategory)
			{
				case 'background':
				myColor.color = e.data.colorOne;
				changeColor();
				break;
			}
		}
		
		private function onAlphaChanged(e:DisplayEvent):void
		{
			switch(e.data.itemCategory)
			{
				case 'background':
				itemAlpha = e.data.alpha / 100;
				changeAlpha();
				break;
			}
		}
	}
}